home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
misc
/
prtfolio
/
sft.arj
/
TMIO.ASM
< prev
next >
Wrap
Assembly Source File
|
1993-07-21
|
21KB
|
847 lines
; serial port routines for ibm-pc, including atari portfolio
; r. henze 17.07.90
; last edit 21.07.93
NAME TMIO
;Unterscheidung der Versionen:
; a86 tmio.asm tmio_ibm.obj : ibm, com1
; a86 =ptf tmio.asm tmio_ptf.obj : portfolio
;82C50 constants:
ser_bas1 equ 402h ;com2
ser_bas0 equ 400h ;com1
rbr equ 0h ;receiver reg
thr equ 0h ;transmitter
ier equ 1h ;interrupt en
iir equ 2h ;interrupt id
lcr equ 3h ;line ctrl
mcr equ 4h ;modem ctrl
lsr equ 5h ;line status
msr equ 6h ;modem status
;interrupt controller:
int_reg equ 807fh ;adr ser vect reg
int_on equ 01h ;enable int
int_off equ 00h ;disable int
#if com2
iintnum equ 0bh ;int number com2
iintena equ 0f7h ;int enable com2
iintdsa equ 08h ;int disable com2
#else
iintnum equ 0ch ;int number com1
iintena equ 0efh ;int enable com1
iintdsa equ 10h ;int disable com1
#endif
;control bytes:
dtr equ 01h
rts equ 02h
thre_mask equ 20h
;miscelaneous definitions
cr equ 0dh
lf equ 0ah
;port_default equ 83h ; 8 bit, 1 stop bit, 1200 baud
port_default equ 0e3h ; 8 bit, 1 stop bit, 9600 baud
strp_top equ 7fh
;memory allocation blocks:
buf_len equ 500h ;input buffer
stk_len equ 200h ;stack
;------------------------------------
DGROUP GROUP _DATA,_BSS
_DATA SEGMENT WORD PUBLIC 'DATA'
public _port_stat
public _tmdp_cnt
tmio_base dw 0
tmio_offc dw 0
tmio_segc dw 0
_port_stat dw 0
port_par dw port_default
;buffer storage
tmdp_cbuf db buf_len dup (00)
tmdp_head dw offset tmdp_cbuf
tmdp_tail dw offset tmdp_cbuf
_tmdp_cnt dw 0
;tmdp_ful dw 0
scratch dw 0
com_port dw 0
int_num dw 000ch ;int number com1
int_ena dw 00efh ;int enable com1
int_dsa dw 0010h ;int disable com1
ctc_flag dw 00 ;control-c flag
_DATA ENDS
_BSS SEGMENT WORD PUBLIC 'BSS'
_BSS ENDS
;------------------------------------
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS: _TEXT, DS: _DATA
public _send_com
public _exit_com
public _tmio_setup
public _receive_com
public _cout
public _put
public _hex
public _hex8
;Control-C abfangen:
public _nobreak
public _get_ctc
;***** aufruf in c:
;extern void nobreak ();
;extern int get_ctc ();
;------------------------------------
;tmio_setup
;sets up serial port
;parmeters : port parameter-byte
;returns : none
;destroys : none
_tmio_setup proc near
push bp
push ax
mov bp,sp
mov ax,[bp+6]
mov port_par,al
mov com_port,ah
cmp com_port,0
je co1
mov int_num,0bh ;int number com2
mov int_ena,0f7h ;int enable com2
mov int_dsa,08h ;int disable com2
jmp co2
co1:
mov int_num,0ch ;int number com1
mov int_ena,0efh ;int enable com1
mov int_dsa,10h ;int disable com1
co2:
push dx
cli
push bx
push es
mov al,int_num
mov ah,35h
int 21h
mov tmio_segc,es
mov tmio_offc,bx
pop es
pop bx
push ds
mov al,int_num
mov ah,25h
mov dx,offset cs:_tmio_intc
mov ds,cs
int 21h
pop ds
sti
call _tmio_init
call _tmio_inon
pop dx
pop ax
pop bp
ret
_tmio_setup endp
;-----------------------------------
;receive_com
;get character from buffer
;parmeters : address where character will be installed
;returns : ax : 1 char fetched, 0 no char fetched
;destroys : none
_receive_com proc near
push bp
push dx
push di
push si
mov bp,sp
mov ax,[bp+10] ;save parameter
cmp _tmdp_cnt,0 ;buffer empty?
jle gete0
push ax ;save char pointer
mov di,tmdp_tail
mov al,[di] ;get char from buffer
mov scratch,al ;and save it
pop ax ;get char pointer back
mov di,ax
mov [di],scratch ;store char at input pointer
inc tmdp_tail ;and increment pointer
mov ax,offset tmdp_cbuf
add ax,buf_len
cmp ax,tmdp_tail
jg get1
mov ax,offset tmdp_cbuf
mov tmdp_tail,ax ;turn pointer back to start
get1: dec _tmdp_cnt ;decrement buffer count
mov ax,1
jmp gete1
gete0: xor ax,ax
gete1: pop si
pop di
pop dx
pop bp
ret
_receive_com endp
;-----------------------------------
; send_com
; sends a char to serial port
; stack : char to send
; returns : ax = 1
; destroys: none
_send_com proc near
push bp
push dx
push di
mov bp,sp
mov ax,[bp+8] ;uebergabe parameter
push ax
mov di,tmio_base
mov dx,lsr
add dx, di
char_wthr:
in al,dx
test al,thre_mask
jz char_wthr
pop ax
mov dx,thr
add dx,di
out dx,al
mov ax,1
pop di
pop dx
pop bp
ret
_send_com endp
;-----------------------------------
; tmio_init : init serial port
; 1200 baud, 8 bits, no parity
; dtr high
; parameters : none
; returns: : none
; destroys: :none
_tmio_init proc near
push ax
push si
push dx
push di
cmp com_port,0
je com1
xor ax,ax
push ds
mov ds,ax
mov di,[ser_bas1]
pop ds
jmp com2
com1:
xor ax,ax
push ds
mov ds,ax
mov di,[ser_bas0]
pop ds
com2:
mov tmio_base,di
call _tmio_inof
mov al,port_par
call _tmio_inpt
#if ptf
;code for portfolio:
mov ax,int_num
call _tmio_sint
#else
;code for standard ibm-pc:
in al,21h
and al,int_ena
out 21h,al
#endif
;set up modem control reg:
mov dx,mcr
add dx,di
#if ptf
;code for portfolio:
mov al,dtr or rts
;fuer dcf-77 uhr (pin4=high (+), pin7=low (-)
; mov al,dtr
#else
;code for standard ibm-pc:
mov al,dtr or rts or 8
;fuer dcf-77 uhr (pin4=high (+), pin7=low (-)
; mov al,dtr or 8
#endif
out dx,al
call _tmio_inon
mov dx,di
in al,dx
pop di
pop dx
pop si
pop